# Link to circuit Diagram # https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/ import RPi.GPIO as GPIO import time GPIO.cleanup() GPIO.setmode(GPIO.BCM) GPIO.setup(25, GPIO.IN) buttonDown = False while True: time.sleep(.1) input = GPIO.input(25) if input: if not buttonDown: buttonDown = True print("button pushed") startTime = time.time() else: if buttonDown: elapsedTime = time.time() - startTime print(elapsedTime) buttonDown = False GPIO.cleanup()